package com.haier.controller.manager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONObject;
import com.haier.dto.hpConstantDto;
import com.haier.service.IHpConstantService;
import com.haier.utils.EmptyUtils;
import com.haier.vo.ResponseVo;

@RestController
@RequestMapping(value = "/hipassjava/manager/hpConstant")
public class ManagerHpConstantContoller {
	private static final Logger logger = LoggerFactory.getLogger(ManagerHpConstantContoller.class);
	@Autowired
	private IHpConstantService iHpConstantService;

	/**
	 * 查询分页
	 */
	@RequestMapping(value = "/page", method = RequestMethod.POST)
	public Object page(@RequestBody hpConstantDto dto) {
		try {
			return ResponseVo.success(iHpConstantService.page(dto));
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return ResponseVo.error();
		}
	}

	/**
	 * 根据区域id查询审核人
	 */
	@RequestMapping(value = "/edit", method = RequestMethod.POST)
	public Object findAuditorByAreaId(@RequestBody JSONObject params) {
		try {
			String hpKey = params.getString("hpKey");
			if (EmptyUtils.isEmpty(hpKey)) {
				return ResponseVo.checkError("key不能为空");
			}
			String hpValue = params.getString("hpValue");
			if (EmptyUtils.isEmpty(hpValue)) {
				return ResponseVo.checkError("value不能为空");
			}
			return iHpConstantService.edit(params);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return ResponseVo.error();
		}
	}

	/**
	 * 修改授权人等级、被授权人等级
	 */
	@RequestMapping(value = "/editAuthorizerLevel", method = RequestMethod.POST)
	public Object editAuthorizerLevel(@RequestBody JSONObject params) {
		try {
			String authorizerLevel = params.getString("authorizerLevel");
			if (EmptyUtils.isEmpty(authorizerLevel)) {
				return ResponseVo.checkError("授权人等级不能为空");
			}

			String passivityAuthorizerLevel = params.getString("passivityAuthorizerLevel");
			if (EmptyUtils.isEmpty(passivityAuthorizerLevel)) {
				return ResponseVo.checkError("被授权人等级不能为空");
			}
			return iHpConstantService.saveOrUpdateLevel(params);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return ResponseVo.error();
		}
	}

	/**
	 * 查询授权人等级、被授权人等级
	 */
	@RequestMapping(value = "/selectAuthorizerLevel", method = RequestMethod.GET)
	public ResponseVo selectAuthorizerLevel() {
		return iHpConstantService.selectAuthorizerLevel();
	}
}
